package com.tierstall.client.view;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;
import com.tierstall.client.presenter.LoginPresenter;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.Label;

public class LoginView extends Composite {

	private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class);
	private LoginPresenter presenter;
	
	  public interface Display {
		  void onLoginClicked(String username, String password, boolean save_session);
	  }

	interface LoginUiBinder extends UiBinder<Widget, LoginView> {
	}

	@UiField TextBox name_box;
	@UiField Button login;
	@UiField PasswordTextBox pw_box;
	@UiField CheckBox save_session;
	@UiField Label username_info;
	@UiField Label password_info;
	 
	public LoginView() {
		initWidget(uiBinder.createAndBindUi(this));
	}
	
	@UiHandler("login")
	void onLoginClicked(ClickEvent event) {
	    if (presenter != null) {
	      presenter.onLoginClicked(name_box.getText(), pw_box.getText(), save_session.getValue());
	    }
	  }


	  public void setPresenter(LoginPresenter presenter) {
	    this.presenter = presenter;
	  }
	  
	  public void enableUsernameInfo(String text){
		  username_info.setVisible(true);
		  username_info.setText(text);
	  }
	  
	  public void disableUsernameInfo(){
		  username_info.setVisible(false);
	  }

	  public void enablePasswordInfo(String text){
		  password_info.setVisible(true);
		  password_info.setText(text);
	  }
	  
	  public void disablePasswordInfo(){
		  password_info.setVisible(false);
	  }

}
